//
//  KVNHouseTableViewCell.m
//  Test1
//
//  Created by KelvinYeung on 15/8/4.
//  Copyright (c) 2015年 KelvinYeung. All rights reserved.
//

#import "KVNHouseTableViewCell.h"



@implementation KVNHouseTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    [self setAccessoryType:UITableViewCellAccessoryNone];
    if(self){
        [self initSubviews];
    }
    return self;

}


- (void) initSubviews{
    
    //[self.imageView setFrame:CGRectMake(10, 10, 80, 60)];
    _defaultImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 8, 100, 74)];
    _titleView = [[UILabel alloc] init];
    _valueView1 = [[UILabel alloc] init];
    _valueView2 = [[UILabel alloc] init];
    _valueView3 = [[UILabel alloc] init];
    _valueView4 = [[UILabel alloc] init];
    _indicatorImageView = [[UIImageView alloc] init];
    
    /*
    _defaultImageView.backgroundColor = [UIColor purpleColor];
    _titleView.backgroundColor = [UIColor redColor];
    _valueView1.backgroundColor = [UIColor grayColor];
    _valueView2.backgroundColor = [UIColor greenColor];
    _valueView3.backgroundColor = [UIColor blueColor];
    */
     
    [self addSubview:_defaultImageView];
    [self addSubview:_titleView];
    [self addSubview:_valueView1];
    [self addSubview:_valueView2];
    [self addSubview:_valueView3];
    [self addSubview:_valueView4];
    [self addSubview:_indicatorImageView];
    
    //对齐
    _valueView4.textAlignment = UITextAlignmentRight;

    //字体大小
    _titleView.font = [UIFont systemFontOfSize:16];
    _valueView1.font = [UIFont systemFontOfSize:14];
    _valueView2.font = [UIFont systemFontOfSize:14];
    _valueView3.font = [UIFont systemFontOfSize:16];
    _valueView4.font = [UIFont systemFontOfSize:12];
    
    //字体颜色
    UIColor  * contentColor = [UIColor colorWithWhite:0.7 alpha:1];
    _valueView1.textColor = contentColor;
    _valueView2.textColor = contentColor;
    _valueView3.textColor = [UIColor redColor];
    _valueView4.textColor = [UIColor redColor];
    

    _titleView.translatesAutoresizingMaskIntoConstraints = NO;
    _valueView1.translatesAutoresizingMaskIntoConstraints = NO;
    _valueView2.translatesAutoresizingMaskIntoConstraints = NO;
    _valueView3.translatesAutoresizingMaskIntoConstraints = NO;
    _valueView4.translatesAutoresizingMaskIntoConstraints = NO;
    _indicatorImageView.translatesAutoresizingMaskIntoConstraints = NO;
    //布局
    //_tableView
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_titleView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:_defaultImageView attribute:NSLayoutAttributeRight multiplier:1 constant:5]];
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_titleView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1 constant:7]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_titleView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:_valueView4 attribute:NSLayoutAttributeLeft multiplier:1 constant:0]];
    
    
    //_valueView1
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_valueView1 attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:_defaultImageView attribute:NSLayoutAttributeRight multiplier:1 constant:5]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_valueView1 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem: _titleView attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_valueView1 attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem: self attribute:NSLayoutAttributeRight multiplier:1 constant:-10]];
    
    
    //_valueView2
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_valueView2 attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:_defaultImageView attribute:NSLayoutAttributeRight multiplier:1 constant:5]];
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_valueView2 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_valueView1 attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_valueView2 attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationLessThanOrEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1 constant:-10]];
  
    
    
    //_valueView3
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_valueView3 attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:_defaultImageView attribute:NSLayoutAttributeRight multiplier:1 constant:5]];
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_valueView3 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_valueView2 attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
    
    //[self addConstraint:[NSLayoutConstraint constraintWithItem:_valueView3 attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1 constant:10]];
    

    
    //_valueView4
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_valueView4 attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1 constant:10]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_valueView4 attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:_indicatorImageView attribute:NSLayoutAttributeLeft multiplier:1 constant:-5]];
    [_valueView4 addConstraint:[NSLayoutConstraint constraintWithItem:_valueView4 attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:50]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_valueView4 attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:_titleView attribute:NSLayoutAttributeRight multiplier:1 constant:0]];
    
    
    //类型图标
    [_indicatorImageView addConstraint:[NSLayoutConstraint constraintWithItem:_indicatorImageView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:15]];
    [_indicatorImageView addConstraint:[NSLayoutConstraint constraintWithItem:_indicatorImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0 constant:15]];
    
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_indicatorImageView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1 constant:-10]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:_indicatorImageView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1 constant:10]];
    
    
}

@end
